package com.xd.hbsys.aqi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xd.hbsys.station.StationService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AQIController {

    @Autowired
    private AQIService aqiService;

    @RequestMapping(value = "/aqi/city/day", produces = "application/json;charset=UTF-8")
    public String day(
            @RequestParam(value = "day", required = false) String day,
            @RequestParam(value = "day0", required = false) String day0,
            @RequestParam(value = "day1", required = false) String day1,
            @RequestParam(value = "city", required = false) String city) {
        if (day != null) {
            return aqiService.queryCityDay(day, city);
        } else if (day0 != null && day1 != null) {
            return aqiService.queryCityDayRange(day0, day1, city);
        }
        return AQIService.RETURN_NULL;
    }

    @RequestMapping(value = "/aqi/city/hour")
    public String hour(
            @RequestParam(value = "date", required = false) String date,
            @RequestParam(value = "date0", required = false) String date0,
            @RequestParam(value = "date1", required = false) String date1,
            @RequestParam(value = "city", required = false) String city) {
        if (date != null) {
            return aqiService.queryCityHour(date, city);
        } else if (date0 != null && date1 != null) {
            return aqiService.queryCityHourRange(date0, date1, city);
        }
        return AQIService.RETURN_NULL;

    }

    @RequestMapping("/aqi/findCityAqiByDay")
    public List<Map<String, Object>> findCityAqiByDay(@RequestParam(value = "t1") String t1, @RequestParam(value = "t2") String t2) {

        try {
            Map<String, Object> map = new HashMap<>();
            map.put("t1", t1);
            map.put("t2", t2);
            return aqiService.findCityAqiByDay(map);
        } catch (Exception e) {
            return null;
        }

    }
    /*获取city_aqi_day最新时间的一条数据*/
    @RequestMapping("/aqi/getMaxtimeAqiDay")
    public Map<String, Object> getMaxtimeAqiDay(){
        return aqiService.getMaxtimeAqiDay();
    }


}
